package ntd.util.frame.action.enums;

import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.modular.extra.ai.FactoryAiOpt;
import ntd.action.ActionAbs;
import ntd.action.bo.ActionInfo;
import ntd.action.bo.ActionOutBo;
import ntd.util.config.common.bo.ComDictVo;
import ntd.util.config.common.enums.FactoryEnum;
import ntd.util.util.UtilEnum;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ActionEnumDict extends ActionAbs {

    @Override
    public ActionInfo info() {
        return new ActionInfo("系统枚举字典info", "action-enum-dict", new ActionEnumDict());
    }

    @Override
    public ActionOutBo handle() {
        List<Map<String, Object>> dictBypass = dictBypass(actionInBo.getDataCode());

        if (ObjectUtil.isNotNull(dictBypass)) {
            return new ActionOutBo(dictBypass);
        }

        List<ComDictVo> maps = UtilEnum.generateDictEnum(FactoryEnum.getEnumClass(actionInBo.getDataCode()));

        return new ActionOutBo(maps);
    }

    public List<Map<String, Object>> dictBypass(String code) {
        switch (code) {
            case "AI_mode_type": return CollStreamUtil.toList(FactoryAiOpt.OPT_VISION_MODEL.cacheListAll(), visionModelDo -> {
                Map<String, Object> map = new HashMap<>();
                map.put("name", visionModelDo.getName());
                map.put("memo", visionModelDo.getName());
                map.put("val", visionModelDo.getCode());
                return map;
            });
            default: return null;
        }
    }

}
